/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author Ej-Dý
 */
package tree;

import java.util.List;
/**
 * Vnitrni forma: blok.
 */
public class BlockTree extends Tree {

    /**
     * Tabulka symbolu.
     */
    private SymTab symTab;
    private  FunTab funTab;
    private List<VlastniProgramTree> vlastniProgram;
    private List<FunTeloTree> fts;

    /**
     * Pozadovana velikost zasobniku.
     */
    private int stackDepth;

    public BlockTree(Position start, Position end, SymTab symTab,FunTab funTab, List<VlastniProgramTree> vlastniProgram,List<FunTeloTree> fts) {
        super(start, end);
        this.symTab = symTab;
        this.funTab = funTab;
        this.vlastniProgram = vlastniProgram;
        this.fts=fts;
    }

    public SymTab getSymTab() {
        return symTab;
    }

     public FunTab getFunTab() {
        return funTab;
    }

    public List<VlastniProgramTree> getVlastniProgram() {
        return vlastniProgram;
    }

    public List<FunTeloTree> getFunTelo() {
        return fts;
    }

    public int getStackDepth() {
        return stackDepth;
    }

    public void setStackDepth(int stackDepth) {
        this.stackDepth = stackDepth;
    }

    @Override
    public void accept(TreeVisitor visitor) {
    visitor.visitBlock(this);
    }

    @Override
    public void generate(Context ctx) {

    for(FunTeloTree ft: fts){
        ft.generate(ctx);
    }
    ctx.println("method main");
    ctx.println("stack " + stackDepth);
    ctx.println("locals " + (symTab.getSize()));

    
    for(VlastniProgramTree vpt: vlastniProgram){
        vpt.generate(ctx);
    }
    
    ctx.println("return");
    ctx.println("end");
    }
    @Override
    public String toString() {
        return String.format("Block %s: [%s, %s , %s]", super.toString(), symTab, funTab, vlastniProgram);
    }


}